package me.ivps.android.themedemo;

import android.content.Intent;
import android.os.Bundle;
import android.support.v7.app.ActionBarActivity;
import android.util.Log;
import android.view.View;

public class MainActivity extends ActionBarActivity {
    
    private static final String TAG = "MainActivity";
    
    int currentTheme;
    
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        currentTheme = SettingUtil.getTheme(this);
        if (currentTheme > 0) {
            Log.d(TAG, "onCreate currentTheme");
            setTheme(currentTheme);
        }
        
        super.onCreate(savedInstanceState);
        
        Log.d(TAG, "onCreate");
        
        setContentView(R.layout.activity_main);
        
        findViewById(R.id.btn_change_theme).setOnClickListener(
                new View.OnClickListener() {
                    
                    @Override
                    public void onClick(View arg0) {
                        switch (currentTheme) {
                            case R.style.myTheme1:
                                currentTheme = R.style.myTheme2;
                                break;
                            
                            default:
                                currentTheme = R.style.myTheme1;
                                break;
                        }
                        
                        SettingUtil.setTheme(MainActivity.this, currentTheme);
                        reload();
                    }
                });
    }
    
    private void reload() {
        Intent intent = getIntent();
        intent.addFlags(Intent.FLAG_ACTIVITY_NO_ANIMATION);
        
        finish();
        startActivity(intent);
    }
    
}
